package com.fx.common;

import com.fx.controller.ExceptionPageController;
import javafx.application.Platform;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ExceptionHandler {

    @Autowired
    private ExceptionPageController exceptionPageController;

    public void showError(Thread t, Throwable e) {
        log.error("异常:",e);
        if (Platform.isFxApplicationThread()) {
            showErrorDialog(e);
        } else {
            log.error("An unexpected error occurred in "+t);
        }
    }

    private void showErrorDialog(Throwable e) {
        log.info("exceptionPageController is null   {}",exceptionPageController == null);
        exceptionPageController.setErrorText(e.getMessage());
        exceptionPageController.openWindow();
    }

}
